package com.example.demo.service;
import com.example.demo.entity.AlterDemand;
import com.example.demo.entity.UpdateCheck;
import com.example.demo.mapper.AlterDemandMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service

public class AlterDemandService {
    @Resource
    AlterDemandMapper alterDemandMapper;

    //  添加需求
    public int addDemand(AlterDemand alterDemand) {
        return alterDemandMapper.addDemand(alterDemand);
    }
    //  更新需求
    public int AlterDemand(AlterDemand alterDemand) {
        return alterDemandMapper.AlterDemand(alterDemand);
    }
    //  审核需求
    @Transactional
    public int updateCheck(UpdateCheck updateCheck) {
//        alterDemandMapper.updateCheck(updateCheck);
        int id = updateCheck.getId();
        if(updateCheck.getIfNew()==0&&updateCheck.getIfCheck()==1)
            alterDemandMapper.insertDemand(updateCheck);
        if(updateCheck.getIfNew()==1&&updateCheck.getIfCheck()==1)
            alterDemandMapper.updateDemand(updateCheck);
        updateCheck.setId(id);
        return alterDemandMapper.updateCheck(updateCheck);
    }

    public int getAlterDemandCounts(String bgProject,String query, int if_check, int time_classification) {
        return alterDemandMapper.getAlterDemandCounts(bgProject,query, if_check, time_classification);
    }

    public List<AlterDemand> getAllAlterDemand(String bgProject,String query, int if_check, int time_classification, int pageStart, int pageSize) {
        return alterDemandMapper.getAllAlterDemand(bgProject,query,if_check, time_classification, pageStart, pageSize);
    }



}
